# 散点图 每个专业 绩点分布
import pandas as pd

from Page.sql import search_average_compulsory_by_major
from pyecharts import options as opts
from pyecharts.charts import Scatter, Timeline, Grid, Page

yy = pd.DataFrame(search_average_compulsory_by_major("医学影像技术"), columns=['班级', '平均绩点', '学分'])
class_gas = yy.groupby('班级').agg({'平均绩点': list, '学分': list})
print(class_gas.iloc[1])

tl = Timeline()
for i in range(len(class_gas)):
    c = Scatter()
    c.add_xaxis(xaxis_data=class_gas.iloc[i]['平均绩点'])
    c.add_yaxis("", class_gas.iloc[i]['学分'], symbol_size=10, color="orange")
    c.set_series_opts()
    c.set_global_opts(
        xaxis_opts=opts.AxisOpts(
            type_="value", splitline_opts=opts.SplitLineOpts(is_show=True)
        ),
        yaxis_opts=opts.AxisOpts(
            type_="value",
            axistick_opts=opts.AxisTickOpts(is_show=True),
            splitline_opts=opts.SplitLineOpts(is_show=True),

        ),
        tooltip_opts=opts.TooltipOpts(is_show=False),
        title_opts=opts.TitleOpts(title="医学影像专业绩点/学分分布图"),
        legend_opts=opts.LegendOpts(is_show=False)
        # visualmap_opts=opts.VisualMapOpts(type_="size", max_=150, min_=20),
    )
    tl.add(c, class_gas.index[i])
    tl.add_schema(is_auto_play=True)
tl.render("医学影像散点图.html")
